package com.eric.common.file;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class JSave {
	
	public void Add (String targetFile,String content) throws IOException {
		FileWriter fw = new FileWriter(targetFile,true);
		fw.write(content+"\r\n");
		fw.close();
	}
	public void Add (File targetFile,String content) throws IOException {
		FileWriter fw = new FileWriter(targetFile,true);
		fw.write(content+"\r\n");
		fw.close();
	}
	public void Add (String targetFileName,List<String> content) throws Exception {
		FileWriter fw = new FileWriter(targetFileName,true);
		
		for (String c : content) {
			fw.write(c+"\r\n");
		}
		fw.close();
	}
	public void Add (File targetFile,List<String> content) throws Exception {
		FileWriter fw = new FileWriter(targetFile,true);

		for (String c : content) {
			fw.write(c+"\r\n");
		}
		fw.close();
	}
	public void Add(String targetFileName,Map<String,List<String>> mp) throws IOException {
		File file = new File(targetFileName);
		PrintWriter pw = new PrintWriter(file);
		for (Entry<String,List<String>> e : mp.entrySet()) {
			pw.println(e.getKey()+"="+e.getValue().toString());
		}
		pw.flush();
		pw.close();
	}
	public void Add(String targetFileName,HashMap<String,Integer> mp) throws IOException {
		File file = new File(targetFileName);
		PrintWriter pw = new PrintWriter(file);
		for (Entry<String,Integer> e : mp.entrySet()) {
			pw.println(e.getKey()+"="+e.getValue().toString());
		}
		pw.flush();
		pw.close();
	}
}
